package com.senseauto.surfacemediacodec;


import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.senseauto.surfacemediacodec.widget.CameraFocusView;
import com.senseauto.surfacemediacodec.widget.MyCameraView;

import java.io.File;


public class RecordActivity extends AppCompatActivity {

    private MyCameraView mCameraView;
    //private DefaultVideoRecorder mVideoRecorder;
    private CameraFocusView mFocusView;
    private String TAG = "RecordActivity";
    long time = 60 * 1000;
    boolean isRecording = false;
    Button btnRecord;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_camera2);

        mCameraView = findViewById(R.id.surface_view);

        btnRecord = findViewById(R.id.btnRecord);
        btnRecord.setOnClickListener(v->{
            recordVideo(v);
        });


        mCameraView.setOnFocusListener(new MyCameraView.FocusListener() {
                                           @Override
                                           public void beginFocus(int x, int y) {
                                               mFocusView.beginFocus(x, y);
                                           }

                                           @Override
                                           public void endFocus() {
                                               mFocusView.endFocus(true);
                                           }
                                       }
        );
    }

    public void recordVideo(View view){
        /*if(!isRecording){
            String outPath = new File(getExternalCacheDir() , "live_pusher.mp4").getAbsolutePath();
            String audioPath = new File(getExternalCacheDir() , "yue.mp3").getAbsolutePath();
            Log.e(TAG, "outPuth="+outPath);
            mVideoRecorder = new DefaultVideoRecorder(RecordActivity.this, mCameraView.getEglContext());
            mVideoRecorder.initMediaParams(audioPath,outPath,1920,1080);

            // getTextureId获取会有延后，所以需要在这里设置
            int textureId = mCameraView.getTextureId();
            Log.e(TAG, "onStart，textureId="+textureId);
            mVideoRecorder.setRenderId(textureId);
            isRecording = true;
            btnRecord.setText("录制中");
            mVideoRecorder.startRecord();
        }else{
            btnRecord.setText("录制");
            isRecording = false;
            mVideoRecorder.stopRecord();

        }*/
    }
}